﻿package com.sh.game.global
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import flash.geom.*;
    import flash.utils.*;

    public class GlobalLayer extends Object
    {
        private var _layers:Dictionary;
        private var _root:Stage;
        private var _glowShape:Shape;
        private var _bitmapDrawer:BitmapScale9Drawer;
        public var mist:Object;
        private var _eventPoint:Point;
        private static var _instance:GlobalLayer;

        public function GlobalLayer()
        {
            this._eventPoint = new Point();
            return;
        }// end function

        public function get root() : Stage
        {
            return this._root;
        }// end function

        public function addRightMouse() : void
        {
            if (this._root)
            {
                if (Config.isRightMouse)
                {
                    this._root.addEventListener("rightMouseDown", this.rightDown);
                    this._root.addEventListener("rightMouseUp", this.rightUp);
                }
                else
                {
                    ExternalInterface.addCallback("rightMouseDown", this.rightMouseDown);
                    ExternalInterface.addCallback("rightMouseUp", this.rightMouseUp);
                }
                this._root.addEventListener(MouseEvent.ROLL_OUT, this.rightUp);
            }
            return;
        }// end function

        private function rightMouseDown(param1:int, param2:int) : void
        {
            this._eventPoint.x = this.root.mouseX;
            this._eventPoint.y = this.root.mouseY;
            ModelProxy.change("mouse", "rightDown", this._eventPoint);
            return;
        }// end function

        private function rightMouseUp(param1:int, param2:int) : void
        {
            this._eventPoint.x = param1;
            this._eventPoint.y = param2;
            ModelProxy.change("mouse", "rightUp", this._eventPoint);
            return;
        }// end function

        private function onMouseMove(event:MouseEvent) : void
        {
            ModelProxy.change("mouse", "rightMove", new Point(event.stageX, event.stageY));
            return;
        }// end function

        private function rightDown(event:MouseEvent) : void
        {
            this._root.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
            ModelProxy.change("mouse", "rightDown", new Point(event.stageX, event.stageY));
            return;
        }// end function

        private function rightUp(event:MouseEvent) : void
        {
            if (event.type == MouseEvent.ROLL_OUT)
            {
                ModelProxy.change("mouse", "mouseOut", null);
            }
            this._root.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
            ModelProxy.change("mouse", "rightUp", new Point(event.stageX, event.stageY));
            return;
        }// end function

        public function init(param1:Stage) : void
        {
            this._root = param1;
            this._layers = new Dictionary();
            this._glowShape = new Shape();
            this._glowShape.visible = false;
            this._root.addChild(this._glowShape);
            return;
        }// end function

        public function get danger() : Shape
        {
            return this._glowShape;
        }// end function

        public function get flashStage() : Stage
        {
            return this._root;
        }// end function

        public function addLayer(param1:String, param2:int = -1) : DisplayObjectContainer
        {
            var _loc_3:* = new Sprite();
            this._layers[param1] = _loc_3;
            this._root.addChild(_loc_3);
            return _loc_3;
        }// end function

        public function regLayer(param1:String, param2:Object) : void
        {
            this._layers[param1] = param2;
            return;
        }// end function

        public function getLayer(param1:String) : Object
        {
            return this._layers[param1];
        }// end function

        public function setLayerRect(param1:String, param2:Rectangle) : void
        {
            var _loc_3:* = this._layers[param1];
            _loc_3.scrollRect = param2;
            return;
        }// end function

        public function setLayerPos(param1:String, param2:int, param3:int) : void
        {
            var _loc_4:* = this._layers[param1];
            this._layers[param1].x = param2;
            _loc_4.y = param3;
            return;
        }// end function

        public static function get instance() : GlobalLayer
        {
            if (!_instance)
            {
                _instance = new GlobalLayer;
            }
            return _instance;
        }// end function

    }
}
